package com.bkhech.rabbitmq;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQConfig
 *  RabbitMQ 配置
 * @author guowm
 * @date 2024-11-19
 */
@Configuration
public class RabbitMQConfig {
    // 定义交换机的名称
    public static final String WECHAT_EXCHANGE = "wechat_exchange";
    // 定义队列的名称
    public static final String WECHAT_QUEUE = "wechat_queue";
    // 定义路由键
    public static final String ROUTEING_KEY_WECHAT_MSG_SEND = "wechat.msg.send";

    // 创建交换机
    @Bean(WECHAT_EXCHANGE)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(WECHAT_EXCHANGE).durable(true).build();
    }

    // 创建队列
    @Bean(WECHAT_QUEUE)
    public Queue queue(){
        return QueueBuilder.durable(WECHAT_QUEUE).build();
    }

    /**
     * 定义队列绑定到交换机的关系
     *     # 多个词
     *     * 一个词
     * @param exchange
     * @param queue
     * @return
     */
    @Bean
    public Binding binding(@Qualifier(WECHAT_EXCHANGE) Exchange exchange, @Qualifier(WECHAT_QUEUE) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("wechat.#").noargs();
    }



}
